local skill = fk.CreateSkill {
  name = "lvshi__ex_nihilo_skill",
}

Fk:loadTranslationTable{
  ["reinforcement_nonbasic"] = "弃置一张非基本牌",
  ["reinforcement_2cards"] = "弃置两张牌",
}

local ls = require "packages/lvshi/utility"
skill:addEffect("cardskill", {
  prompt = "#lvshi__ex_nihilo_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = Util.CanUseToSelf,
  on_use = function(self, room, use)
    local choice = ls.strategytrickuse(use.from, use.card, "ex_nihilo_scheme", "ex_nihilo_courage")
    use.extra_data = use.extra_data or {}
    use.extra_data.strategy = choice
  end,
  on_effect = function(self, room, effect)
    if effect.to.dead then return end
    if effect.extra_data.strategy == "ex_nihilo_scheme" then
      room:askToGuanxing(effect.to, { cards = room:getNCards(2 + effect.to:getMark("@ls__qizuo_guanxing")) })
    end
    room:drawCards(effect.to, 2, skill.name)
    if effect.extra_data.strategy == "ex_nihilo_courage" then
      local to = effect.to
      room:drawCards(to, 1, skill.name)
      if to.dead then return end
      local all_choices = { "reinforcement_nonbasic", "reinforcement_2cards" }
      local choices = table.clone(all_choices)
      if #table.filter(to:getCardIds("he"), function (id)
        return not to:prohibitDiscard(id)
      end) < 2 then
        table.remove(choices, 2)
      end
      if not table.find(to:getCardIds("he"), function (id)
        return Fk:getCardById(id).type ~= Card.TypeBasic and not to:prohibitDiscard(id)
      end) then
        table.remove(choices, 1)
      end
      if #choices == 0 then return end
      local choice = room:askToChoice(to, {
        choices = choices,
        skill_name = skill.name,
        all_choices = all_choices,
      })
      if choice == "reinforcement_nonbasic" then
        room:askToDiscard(to, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = skill.name,
          pattern = ".|.|.|.|.|^basic",
          cancelable = false,
        })
      else
        room:askToDiscard(to, {
          min_num = 2,
          max_num = 2,
          include_equip = true,
          skill_name = skill.name,
          cancelable = false,
        })
      end
    end
  end,
})

return skill